﻿using AutoMapper;
using ProjectManageSystemApi.DbEntity;
using ProjectManageSystemApi.Models;
using ProjectManageSystemApi.Models.ProjectItemPriceRecordModel;
using System.Collections.Generic;

namespace ProjectManageSystemApi.Services.Impl
{
    public class ProjectItemPriceRecordServices : ServicesBase, IProjectItemPriceRecordServices
    {
        public ProjectItemPriceRecordServices(IFreeSql fsql, IMapper mapper) : base(fsql, mapper) 
        {
        
        }
        public PageVo<List<ProjectItemPriceRecordDto>> Get(PageBo<ProjectItemPriceRecordParams> pageBo) 
        {
            var data = _fsql.Select<ProjectItemPriceRecord>()
                .Include(x => x.UserInfo)
                .Where(x => x.ItemId == pageBo.Param.ItemId)
                .OrderByDescending(x => x.CreateTime);

            var result = new Models.PageVo<List<ProjectItemPriceRecordDto>>();
            result.Total = data.Count();
            result.Page = pageBo.Page;
            result.Size = pageBo.Size;
            result.Datas = _mapper.Map<List<ProjectItemPriceRecordDto>>(data.Page(pageBo.Page, pageBo.Size).ToList());

            return result;
        }

    }
}
